#!/bin/bash

log-debug "creating admin registration entry..."
docker compose exec -T spire-server \
    /opt/spire/bin/spire-server entry create \
    -parentID "spiffe://domain.test/spire/agent/x509pop/$(fingerprint conf/agent/agent.crt.pem)" \
    -spiffeID "spiffe://domain.test/admin" \
    -selector "unix:uid:1000" \
    -admin \
    -x509SVIDTTL 0
check-synced-entry "spire-agent" "spiffe://domain.test/admin"

log-debug "running x509pop test..."
docker compose exec -u 1000 -T spire-agent /opt/spire/conf/agent/node-attestation -testStep x509pop || fail-now "failed to check x509pop attestion"
